#include <iostream>
#include <fstream>
#include <vector>
#include "../utils.h"
#include "../combine.h"
#include <cmath>
using namespace std;


/*
 * vector<bomba> getBest(const vector<pair<bset,bomba> >& initial, int k, int csets, int m);
 */

int main(int argc, char *argv[]) {
	if (argc!=2) {
		cout << "USO: testCombine archivoEntrada" << endl;
		return 1;
	}
	ifstream in(argv[1]);
	int n,m; string s;
	in >> n >> m;
	vector<pair<bset, bomba> > initial(n);
	forn(i,n) {
		in >> s;
		initial[i].second.x=i;
		forn(j,m) initial[i].first[j]=(s[j]=='1');
	}
	forsn(k,1,n) {
		cout << "K=" << k << endl;
		vector<bomba> r=getBest(initial, k, 10, m);
		forn(i,k) {
			cout << r[i].x << "(";
			forn(j,m) cout << (initial[int(round(r[i].x))].first[j]?'1':'0');
			cout << ") "; 
		}
		cout << endl;
		bset rr;
		forn(i,k) rr|=initial[int(round(r[i].x))].first;
		forn(i,m) cout << (rr[i]?'1':'0');
		cout << endl << endl;
	}
	return 0;
}
